home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997 January / Macworld (1997-01).dmg / Shareware World / Utilities / Data & Time Management / MacCalendar / Src / MacCalendarSetup.c < prev    next >
C/C++ Source or Header  |  1994-10-20  |  16KB  |  726 lines

  1. /*                                    MacCalendarSetup.c                                */
  2. /*
  3.  * MacCalendarSetup.c
  4.  * Copyright © 1993-94 Apple Computer Inc. All rights reserved.
  5.  * Set the configuration parameters for MacCalendar
  6.  *
  7.  *    File Type            APPL
  8.  *    File Creator        SCCF    -- registered with DTS
  9.  */
  10.  
  11. #ifndef  SystemSevenOrLater
  12. #define  SystemSevenOrLater    1
  13. #endif
  14.  
  15. #include <Dialogs.h>
  16. #include <Errors.h>
  17. #include <Fonts.h>
  18. #include <Memory.h>
  19. #include <Menus.h>
  20. #include <Quickdraw.h>
  21. #include <Resources.h>
  22. #include <SegLoad.h>
  23. #include <ToolUtils.h>
  24. #include <Types.h>
  25. #include "MacCalendarSetup.h"
  26.  
  27. #ifdef __powerc
  28. QDGlobals            qd;        /* This is not automatically defined on PowerPC        */
  29. #endif
  30. MenuHandle            gAppleMenu;
  31. MenuHandle            gFileMenu;
  32. MenuHandle            gEditMenu;
  33. MenuHandle            gFontMenu;
  34. MenuHandle            gFontSizeMenu;
  35. MenuHandle            gFirstDayMenu;
  36. DialogPtr            gSetupDialog;
  37. short                gAppResourceFile;
  38.  
  39. short                gPrefFileRefNum;
  40. SavedSettingsHandle    gSettingHandle = NULL;
  41. SavedSettings        *gSettingPtr;
  42. #define SET            (*gSettingPtr)
  43. DateTimeRec            gNow;
  44.  
  45. void                        InitApplication(void);
  46. void                        SetupDialog(void);
  47. void                        SetThisDayName(
  48.         short                    itemNumber,
  49.         ConstStr255Param        itemText
  50.     );
  51. Boolean                        DoDialog(void);
  52. pascal void                    DrawCalendarUserItem(
  53.         DialogPtr                theDialog,
  54.         short                    itemNumber
  55.     );
  56. pascal void                    DrawVersionUserItem(
  57.         DialogPtr                theDialog,
  58.         short                    itemNumber
  59.     );
  60. pascal void                    DrawDayNameUserItem(
  61.         DialogPtr                theDialog,
  62.         short                    itemNumber
  63.     );
  64. void                        RebuildDayNameText(void);
  65. void                        AddThisDayName(
  66.         short                    dayNumber
  67.     );
  68. OSErr                        ReadCurrentParameters(
  69.         SignedByte                permission
  70.     );
  71. void                        SaveNewParameters(void);
  72. OSErr                        OpenPreferenceFile(
  73.         OSType                    prefFileType,
  74.         OSType                    prefFileCreator,
  75.         SignedByte                permission,
  76.         short                    *prefVRefNum,
  77.         StringPtr                prefFileName
  78.     );
  79. void                        NonFatalError(
  80.         OSErr                    errorStatus,
  81.         short                    errorMsgID
  82.     );
  83. void                        FatalError(
  84.         OSErr                    errorStatus,
  85.         short                    errorMsgID
  86.     );
  87. void                        ErrorAlert(
  88.         short                    alertID,
  89.         OSErr                    errorStatus,
  90.         short                    errorMsgID
  91.     );
  92.  
  93.  
  94. void
  95. main(void)
  96. {
  97.         unsigned long            nowSeconds;
  98.         Boolean                    updateNeeded;
  99.         
  100.         InitApplication();
  101.         GetDateTime(&nowSeconds);
  102.         Secs2Date(nowSeconds, &gNow);
  103.         gSetupDialog = GetNewDialog(DLOG_Setup, NULL, (WindowPtr) -1L);
  104.         if (gSetupDialog != NULL) {
  105.             if (ReadCurrentParameters(fsRdWrPerm) != noErr) {
  106.                 DisposeDialog(gSetupDialog);
  107.                 NoteAlert(ALRT_NoPreferences, NULL);
  108.             }
  109.             else {
  110.                 SetupDialog();
  111.                 updateNeeded = DoDialog();
  112.                 DisposeDialog(gSetupDialog);
  113.                 if (updateNeeded
  114.                  && gPrefFileRefNum != 0
  115.                  && NoteAlert(ALRT_WaitForReboot, NULL) == kOKButton)
  116.                     SaveNewParameters();
  117.                 if (gPrefFileRefNum != 0)
  118.                     CloseResFile(gPrefFileRefNum);
  119.             }
  120.         }
  121.         ExitToShell();
  122. }
  123.  
  124. Boolean
  125. DoDialog(void)
  126. {
  127.         short                itemHit;
  128.         short                itemType;
  129.         Handle                itemHandle;
  130.         Rect                itemRect;
  131.         short                i;
  132.         Str255                work;
  133.         Boolean                redraw;
  134.         long                newFontSize;
  135.         
  136.         ShowWindow(gSetupDialog);
  137.         do {
  138.             ModalDialog(NULL, &itemHit);
  139.             GetDItem(
  140.                 gSetupDialog,
  141.                 itemHit,
  142.                 &itemType,
  143.                 &itemHandle,
  144.                 &itemRect
  145.             );
  146.             redraw = FALSE;
  147.             switch (itemHit) {
  148.             case kFontNamePopupItem:
  149.                 i = GetCtlValue((ControlHandle) itemHandle);
  150.                 GetItem(gFontMenu, i, work);
  151.                 if (EqualString(SET.fontName, work, FALSE, FALSE) == FALSE) {
  152.                     pstrcpy(SET.fontName, work);
  153.                     redraw = TRUE;
  154.                 }
  155.                 break;
  156.             case kFontSizePopupItem:
  157.                 i = GetCtlValue((ControlHandle) itemHandle);
  158.                 GetItem(gFontSizeMenu, i, work);
  159.                 StringToNum(work, &newFontSize);
  160.                 if (newFontSize != SET.fontSize) {
  161.                     SET.fontSize = newFontSize;
  162.                     redraw = TRUE;
  163.                 }
  164.                 break;
  165.             case kFirstDayPopupItem:
  166.                 i =    GetCtlValue((ControlHandle) itemHandle);
  167.                 if (i != SET.firstDayOfWeek) {
  168.                     SET.firstDayOfWeek = i;
  169.                     redraw = TRUE;
  170.                 }
  171.                 break;
  172. #if DEBUG
  173.             /*
  174.              * This lets us test the drawing algorithm without rebuilding the
  175.              * actual status bar and rebooting the machine.
  176.              */
  177.             case kPrevMonth:
  178.                 if (--gNow.month < 1) {
  179.                     gNow.month = 12;
  180.                     --gNow.year;
  181.                 }
  182.                 redraw = TRUE;
  183.                 break;
  184.             case kNextMonth:
  185.                 if (++gNow.month > 12) {
  186.                     gNow.month = 1;
  187.                     ++gNow.year;
  188.                 }
  189.                 redraw = TRUE;
  190.                 break;
  191. #endif
  192.             default:
  193.                 if (itemHit >= kSundayText && itemHit <= kSaturdayText)
  194.                     redraw = TRUE;
  195.                 break;
  196.             }
  197.             if (redraw)
  198.                 DrawCalendarUserItem(gSetupDialog, kCalendarUserItem);
  199.         } while (itemHit != kOKButton && itemHit != kCancelButton);
  200.         return (itemHit == kOKButton);
  201. }
  202.  
  203. pascal void
  204. DrawDayNameUserItem(
  205.         DialogPtr                theDialog,
  206.         short                    itemNumber
  207.     )
  208. {
  209.         short                    itemType;
  210.         Handle                    itemHandle;
  211.         Rect                    itemRect;
  212.         Rect                    dayNameRect;
  213.         short                    i;
  214.         Str255                    work;
  215.         Intl1Rec                **itlHandle;
  216.         GrafPtr                    savePort;
  217.         short                    saveFontNumber;
  218.         short                    saveFontSize;
  219.         
  220.         GetPort(&savePort);
  221.         SetPort(theDialog);
  222.         saveFontNumber = theDialog->txFont;
  223.         saveFontSize = theDialog->txSize;
  224.         GetDItem(
  225.             theDialog,
  226.             itemNumber,
  227.             &itemType,
  228.             &itemHandle,
  229.             &dayNameRect
  230.         );
  231.         itlHandle = (Intl1Rec **) IUGetIntl(1);
  232.         for (i = 0; i < 7; i++) {
  233.             /*
  234.              * Get the string, abbreviate it, and draw it in the
  235.              * day name rectangle, tabbed over the associated
  236.              * edit text area. Messy, but it looks nicer.
  237.              */
  238.             pstrcpy(work, (**itlHandle).days[i]);
  239.             GetDItem(
  240.                 theDialog,
  241.                 kSundayText + i,
  242.                 &itemType,
  243.                 &itemHandle,
  244.                 &itemRect
  245.             );
  246.             itemRect.top = dayNameRect.top;
  247.             itemRect.bottom = dayNameRect.bottom;
  248.             TextBox(
  249.                 &work[1],
  250.                 (**itlHandle).abbrLen,
  251.                 &itemRect,
  252.                 teJustLeft
  253.             );
  254.         }
  255.         TextFont(saveFontNumber);
  256.         TextSize(saveFontSize);
  257.         SetPort(savePort);
  258. }
  259.  
  260. pascal void
  261. DrawCalendarUserItem(
  262.         DialogPtr                theDialog,
  263.         short                    itemNumber
  264.     )
  265. {
  266.         short                    itemType;
  267.         Handle                    itemHandle;
  268.         Rect                    itemRect;
  269.         short                    fontNumber;
  270.         GrafPtr                    savePort;
  271.         short                    saveFontNumber;
  272.         short                    saveFontSize;
  273.         RgnHandle                saveRgn;
  274.         
  275.         RebuildDayNameText();
  276.         GetPort(&savePort);
  277.         SetPort(theDialog);
  278.         saveFontNumber = theDialog->txFont;
  279.         saveFontSize = theDialog->txSize;
  280.         GetDItem(
  281.             theDialog,
  282.             itemNumber,
  283.             &itemType,
  284.             &itemHandle,
  285.             &itemRect
  286.         );
  287.         EraseRect(&itemRect);
  288.         FrameRect(&itemRect);
  289.         GetFNum(SET.fontName, &fontNumber);
  290.         saveRgn = NewRgn();
  291.         GetClip(saveRgn);
  292.         ClipRect(&itemRect);
  293.         DrawCalendar(
  294.             gNow.year,
  295.             gNow.month,
  296.             SET.firstDayOfWeek,
  297.             SET.dateString,
  298.             &itemRect,
  299.             fontNumber,
  300.             SET.fontSize
  301.         );
  302.         SetClip(saveRgn);
  303.         DisposeRgn(saveRgn);
  304.         TextFont(saveFontNumber);
  305.         TextSize(saveFontSize);
  306.         SetPort(savePort);
  307. }
  308.  
  309. pascal void
  310. DrawVersionUserItem(
  311.         DialogPtr                theDialog,
  312.         short                    itemNumber
  313.     )
  314. {
  315.         short                    itemType;
  316.         Handle                    itemHandle;
  317.         Rect                    itemRect;
  318.         GrafPtr                    savePort;
  319.         short                    saveFontNumber;
  320.         short                    saveFontSize;
  321.         FontInfo                info;
  322.         
  323.         GetPort(&savePort);
  324.         SetPort(theDialog);
  325.         saveFontNumber = theDialog->txFont;
  326.         saveFontSize = theDialog->txSize;
  327.         GetDItem(
  328.             theDialog,
  329.             itemNumber,
  330.             &itemType,
  331.             &itemHandle,
  332.             &itemRect
  333.         );
  334.         EraseRect(&itemRect);
  335.         TextFont(geneva);
  336.         TextSize(9);
  337.         GetFontInfo(&info);
  338.         MoveTo(itemRect.left, itemRect.top + info.ascent);
  339.         DrawString("\p" kVersionIdent);
  340.         TextFont(saveFontNumber);
  341.         TextSize(saveFontSize);
  342.         SetPort(savePort);
  343. }
  344.  
  345. void
  346. RebuildDayNameText(void)
  347. {
  348.         short                        i;
  349.         
  350.         SET.dateString[0] = 0;
  351.         if (SET.firstDayOfWeek == kFirstIsMonday) {
  352.             for (i = kMondayText; i <= kSaturdayText; i++)
  353.                 AddThisDayName(i);
  354.             AddThisDayName(kSundayText);
  355.         }
  356.         else {
  357.             for (i = kSundayText; i <= kSaturdayText; i++)
  358.                 AddThisDayName(i);
  359.         }
  360.         SET.dateString[++SET.dateString[0]] = 0;
  361. }
  362.  
  363. void
  364. AddThisDayName(
  365.         short                    dayNumber
  366.     )
  367. {
  368.         short                    itemType;
  369.         Handle                    itemHandle;
  370.         Rect                    itemRect;
  371.         Str255                    work;
  372.  
  373.         GetDItem(
  374.             gSetupDialog,
  375.             dayNumber,
  376.             &itemType,
  377.             &itemHandle,
  378.             &itemRect
  379.         );
  380.         GetIText(itemHandle, work);
  381.         BlockMove(
  382.             work,
  383.             &SET.dateString[SET.dateString[0] + 1],
  384.             work[0] + 1
  385.         );
  386.         SET.dateString[0] += (work[0] + 1);
  387. }
  388.  
  389. void
  390. SetupDialog(void)
  391. {
  392.         short                nMenuItems;
  393.         short                i;
  394.         Str255                work;
  395.         Str255                fontSizeText;
  396.         short                itemType;
  397.         Handle                itemHandle;
  398.         Rect                itemRect;
  399.         StringPtr            dayName;
  400.  
  401. #ifndef MPW        /* These are not in ETO 13, but they are in Think 7.0    */
  402.         SetDialogDefaultItem(gSetupDialog, kOKButton);
  403.         SetDialogCancelItem(gSetupDialog, kCancelButton);
  404. #endif
  405.         /*
  406.          * Set the font name popup menu
  407.          */
  408.         nMenuItems = CountMItems(gFontMenu);
  409.         for (i = 1; i <= nMenuItems; i++) {
  410.             GetItem(gFontMenu, i, work);
  411.             if (EqualString(work, SET.fontName, FALSE, FALSE))
  412.                 break;
  413.         }
  414.         if (i <= nMenuItems) {
  415.             GetDItem(
  416.                 gSetupDialog,
  417.                 kFontNamePopupItem,
  418.                 &itemType,
  419.                 &itemHandle,
  420.                 &itemRect
  421.             );
  422.             SetCtlValue((ControlHandle) itemHandle, i);
  423.         }
  424.         /*
  425.          * Set the font size popup menu
  426.          */
  427.         nMenuItems = CountMItems(gFontSizeMenu);
  428.         NumToString(SET.fontSize, fontSizeText);
  429.         for (i = 1; i <= nMenuItems; i++) {
  430.             GetItem(gFontSizeMenu, i, work);
  431.             if (EqualString(work, fontSizeText, FALSE, FALSE))
  432.                 break;
  433.         }
  434.         if (i <= nMenuItems) {
  435.             GetDItem(
  436.                 gSetupDialog,
  437.                 kFontSizePopupItem,
  438.                 &itemType,
  439.                 &itemHandle,
  440.                 &itemRect
  441.             );
  442.             SetCtlValue((ControlHandle) itemHandle, i);
  443.         }
  444.         /*
  445.          * Set the first day popup menu
  446.          */
  447.         GetDItem(
  448.             gSetupDialog,
  449.             kFirstDayPopupItem,
  450.             &itemType,
  451.             &itemHandle,
  452.             &itemRect
  453.         );
  454.         SetCtlValue(
  455.             (ControlHandle) itemHandle,
  456.             SET.firstDayOfWeek
  457.         );
  458.         /*
  459.          * Set the calendar drawing procedure
  460.          */
  461.         GetDItem(
  462.             gSetupDialog,
  463.             kCalendarUserItem,
  464.             &itemType,
  465.             &itemHandle,
  466.             &itemRect
  467.         );
  468.         SetDItem(
  469.             gSetupDialog,
  470.             kCalendarUserItem,
  471.             itemType,
  472.             (Handle) DrawCalendarUserItem,
  473.             &itemRect
  474.         );
  475.         /*
  476.          * Setup the day name user item
  477.          */
  478.         GetDItem(
  479.             gSetupDialog,
  480.             kDayNameUserItem,
  481.             &itemType,
  482.             &itemHandle,
  483.             &itemRect
  484.         );
  485.         SetDItem(
  486.             gSetupDialog,
  487.             kDayNameUserItem,
  488.             itemType,
  489.             (Handle) NewUserItemProc(DrawDayNameUserItem),
  490.             &itemRect
  491.         );
  492.         /*
  493.          * Setup the version number user item
  494.          */
  495.         GetDItem(
  496.             gSetupDialog,
  497.             kVersionUserItem,
  498.             &itemType,
  499.             &itemHandle,
  500.             &itemRect
  501.         );
  502.         SetDItem(
  503.             gSetupDialog,
  504.             kVersionUserItem,
  505.             itemType,
  506.             (Handle) NewUserItemProc(DrawVersionUserItem),
  507.             &itemRect
  508.         );
  509.         /*
  510.          * Move the current date string into the dialog edit records.
  511.          */
  512.         dayName = (StringPtr) &SET.dateString[1];
  513.         i = (SET.firstDayOfWeek == kFirstIsSunday)
  514.             ? kSundayText : kMondayText;
  515.         for (; i <= kSaturdayText; i++) {
  516.             SetThisDayName(i, dayName);
  517.             dayName = (StringPtr) &dayName[dayName[0] + 1];
  518.         }
  519.         if (SET.firstDayOfWeek == kFirstIsMonday)
  520.             SetThisDayName(kSundayText, dayName);
  521. }
  522.  
  523. void
  524. SetThisDayName(
  525.         short                    itemNumber,
  526.         ConstStr255Param        itemText
  527.     )
  528. {
  529.         short                itemType;
  530.         Handle                itemHandle;
  531.         Rect                itemRect;
  532.  
  533.         GetDItem(
  534.             gSetupDialog,
  535.             itemNumber,
  536.             &itemType,
  537.             &itemHandle,
  538.             &itemRect
  539.         );
  540.         SetIText(itemHandle, itemText);
  541. }
  542.  
  543. OSErr
  544. ReadCurrentParameters(
  545.         SignedByte                permission
  546.     )
  547. {
  548.         OSErr                    status;
  549.         Str255                    work;
  550.         short                    saveResFile;
  551.         long                    tempLong;
  552.         Str255                    prefResourceName;
  553.     
  554.         GetIndString(prefResourceName, STRN_Strings, kStrPrefName);
  555.         saveResFile = CurResFile();
  556.         status = OpenPreferenceFile(
  557.                     kPrefFileType,
  558.                     kPrefFileCreator,
  559.                     permission,
  560.                     &gPrefFileRefNum,
  561.                     work
  562.                 );
  563.         if (status == noErr) {
  564.             UseResFile(gPrefFileRefNum);
  565.             gSettingHandle = (SavedSettingsHandle) Get1NamedResource(
  566.                     kPrefResourceType,
  567.                     prefResourceName
  568.                 );
  569.             if (gSettingHandle != NULL) {
  570.                 /*
  571.                  * Make sure we're sailing on the same ship.
  572.                  */
  573.                 MoveHHi((Handle) gSettingHandle);
  574.                 HLock((Handle) gSettingHandle);
  575.                 gSettingPtr = (*gSettingHandle);
  576.                 if (GetHandleSize((Handle) gSettingHandle) != sizeof (SavedSettings)
  577.                  || SET.signature != kApplicationCreator
  578.                  || SET.prefVersion != kPrefVersion
  579.                  || SET.firstDayOfWeek < kFirstIsSunday
  580.                  || SET.firstDayOfWeek > kFirstIsMonday) {
  581.                      RmveResource((Handle) gSettingHandle);
  582.                      DisposeHandle((Handle) gSettingHandle);
  583.                      gSettingHandle = NULL;
  584.                 }
  585.             }
  586.             if (gSettingHandle == NULL) {
  587.                 /*
  588.                  * Build a default SavedSettings record.
  589.                  */
  590.                 gSettingHandle = (SavedSettingsHandle)
  591.                             NewHandleClear(sizeof (SavedSettings));
  592.                 if (gSettingHandle == NULL)
  593.                     status = MemError();
  594.                 else {
  595.                     MoveHHi((Handle) gSettingHandle);
  596.                     HLock((Handle) gSettingHandle);
  597.                     gSettingPtr = (*gSettingHandle);
  598.                     SET.signature = kApplicationCreator;
  599.                     SET.prefVersion = kPrefVersion;
  600.                     UseResFile(saveResFile);
  601.                     GetIndString(SET.fontName, STRN_Strings, kStrFontName);
  602.                     GetIndString(work, STRN_Strings, kStrFontSize);
  603.                     StringToNum(work, &tempLong);
  604.                     SET.fontSize = tempLong;
  605.                     GetIndString(work, STRN_Strings, kStrFirstDayOfWeek);
  606.                     StringToNum(work, &tempLong);
  607.                     SET.firstDayOfWeek = tempLong;
  608.                     GetIndString(SET.dateString, STRN_Strings, kStrDayName);
  609.                     if (gPrefFileRefNum != 0) {
  610.                         UseResFile(gPrefFileRefNum);
  611.                         AddResource(
  612.                             (Handle) gSettingHandle,
  613.                             kPrefResourceType,
  614.                             UniqueID(kPrefResourceType),
  615.                             prefResourceName
  616.                         );
  617.                         if (ResError() == noErr)
  618.                             WriteResource((Handle) gSettingHandle);
  619.                     }
  620.                 }
  621.             }
  622.         }
  623.         UseResFile(saveResFile);
  624.         return (status);
  625. }
  626.  
  627. void
  628. SaveNewParameters(void)
  629. {
  630.         short                    saveResFile;
  631.         OSErr                    status;
  632.         
  633.         saveResFile = CurResFile();
  634.         UseResFile(gPrefFileRefNum);
  635.         status = ResError();
  636.         if (status == noErr)
  637.             ChangedResource((Handle) gSettingHandle);
  638.         status = ResError();
  639.         if (status == noErr)
  640.             UpdateResFile(gPrefFileRefNum);
  641.         status = ResError();
  642.         if (status != noErr)
  643.             NonFatalError(status, kMsgWritingPrefResource);
  644.         UseResFile(saveResFile);
  645. }
  646.  
  647. void
  648. InitApplication(void)
  649. {
  650.         Handle                    menuBarHdl;
  651.         
  652.         MaxApplZone();
  653.         InitGraf(&qd.thePort);
  654.         InitFonts();
  655.         InitWindows();
  656.         InitMenus();
  657.         TEInit();
  658.         InitDialogs(0);
  659.         HNoPurge((Handle) GetCursor(watchCursor));
  660.         SetCursor(*GetCursor(watchCursor));
  661.         menuBarHdl = GetNewMBar(MBAR_MenuBar);
  662.         SetMenuBar(menuBarHdl);
  663.         gAppleMenu = GetMHandle(MENU_Apple);
  664.         gFileMenu = GetMHandle(MENU_File);
  665.         gEditMenu = GetMHandle(MENU_Edit);
  666.         gFirstDayMenu = GetMHandle(MENU_FirstDay);
  667.         AddResMenu(GetMHandle(MENU_Apple), 'DRVR');
  668.         DrawMenuBar();
  669.         gFontMenu = GetMenu(MENU_Font);
  670.         AddResMenu(gFontMenu, 'FONT');
  671.         gFontSizeMenu = GetMenu(MENU_FontSize);
  672.         gAppResourceFile = CurResFile();
  673.         InitCursor();
  674. }
  675.  
  676. void
  677. NonFatalError(
  678.         OSErr                    errorStatus,
  679.         short                    errorMsgID
  680.     )
  681. {
  682.         ErrorAlert(ALRT_NonFatalError, errorStatus, errorMsgID);
  683. }
  684.  
  685. void
  686. FatalError(
  687.         OSErr                    errorStatus,
  688.         short                    errorMsgID
  689.     )
  690. {
  691.         ErrorAlert(ALRT_FatalError, errorStatus, errorMsgID);
  692. }
  693.  
  694. void
  695. ErrorAlert(
  696.         short                    alertID,
  697.         OSErr                    errorStatus,
  698.         short                    errorMsgID
  699.     )
  700. {
  701.         Handle                    errorTextHdl;
  702.         Str15                    errorStatusText;
  703.         short                    userChoice;
  704.         Str255                    errorMsgText;
  705.         Str255                    errorText;
  706.         short                    saveResFile;
  707.         
  708.         saveResFile = CurResFile();
  709.         UseResFile(gAppResourceFile);
  710.         GetIndString(errorMsgText, STRN_Messages, errorMsgID);
  711.         NumToString(errorStatus, errorStatusText);
  712.         errorTextHdl = GetResource('Estr', errorStatus);
  713.         if (errorTextHdl != NULL)
  714.             pstrcpy(errorText, *errorTextHdl);
  715.         else {
  716.             GetIndString(errorText, STRN_Messages, kMsgSystemError);
  717.         }
  718.         ParamText(errorStatusText, errorText, errorMsgText, "\p");
  719.         userChoice = StopAlert(alertID, NULL);
  720.         UseResFile(saveResFile);
  721.         if (alertID == ALRT_FatalError || userChoice == kOKButton)
  722.             ExitToShell();
  723. }
  724.  
  725.  
  726.